package com.ny.demo518;

import java.util.*;

//主程序类，包含程序入口main方法
public class Demo {
    public static void main(String[] args) {
        TestSet testSet = new TestSet();//创建员工管理类对象
        Set<Emp> set = new HashSet<>();//创建员工集合
        Emp emp = new Emp();//创建员工对象
        boolean flag = true;//循环控制标志

        while (flag) {//主菜单循环
            System.out.println("欢迎来到员工系统");
            System.out.println("0.退出系统");
            System.out.println("1.添加员工");
            System.out.println("2.查询所有的员工");
            System.out.println("3.根据员工姓名查询员工信息");
            System.out.println("4.删除员工信息");
            System.out.println("5.根据员工编号查询员工信息");
            System.out.println("6.根据员工编号修改年龄");

            System.out.println("请选择功能");

            Scanner scanner = new Scanner(System.in);
            int n = scanner.nextInt();//读取用户选择

            switch (n) {
                case 0://退出系统
                    System.out.println("退出系统");
                    flag = false;
                    break;

                case 1://添加员工
                    System.out.println("欢迎来到添加的界面");
                    System.out.println("请输入员工的编号:");
                    String addNumber = scanner.next();
                    System.out.println("请输入员工的姓名:");
                    String addName = scanner.next();
                    System.out.println("请输入员工的年龄:");
                    int addAge = scanner.nextInt();
                    Emp addEmp = new Emp(addNumber, addName, addAge);
                    testSet.addEmp(set, addEmp);

                    System.out.println(set);

                    break;

                case 2://查询所有员工
                    System.out.println("查询所有的员工");
                    testSet.findAllEmp(set);
                    break;

                case 3:
                    System.out.println("根据员工姓名查询员工信息");
                    System.out.println("请输入需要查询的员工姓名:");
                    String empName = scanner.next();
                    emp = testSet.findEmpName(set, empName);
                    System.out.println(emp);
                    break;

                case 4:
                    System.out.println("删除员工信息");
                    System.out.println("请输入需要删除员工编号:");
                    String empNumber = scanner.next();
                    testSet.deleteEmp(set, empNumber);
                    System.out.println(set);
                    break;

                case 5:
                    System.out.println("根据员工编号查询员工信息");
                    System.out.println("请输入需要查询的员工编号");
                    String eId = scanner.next();

                    emp = testSet.findEmpNumber(set, eId);
                    System.out.println(emp);
                    break;

                case 6:
                    System.out.println("根据工号修改年龄");
                    System.out.println("请输入需要查询的员工工号");
                    String updateNumber = scanner.next();
                    System.out.println("请输入需要修改的年龄");
                    int updateAge = scanner.nextInt();

                    emp = testSet.findEmpNumber(set, updateNumber);
                    emp.setAge(updateAge);
                    testSet.updateEmp(set, emp);
                    System.out.println(set);
                    break;
            }
        }
    }
}
